package com.hornsun.healthIndex.API;

import com.google.common.base.Preconditions;
import com.hornsun.domain.dbo.HealthIndex;
import com.hornsun.repository.HealthIndexRepository;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * Created by 编译中... on 2018/1/29.
 */
@RestController
@RequestMapping("/api/healthIndex")
public class HealthIndexAPI {
    private HealthIndexRepository healthIndexRepository;
    /**
     * 新增健康指标
     */
    @PostMapping("/addHealthIndex")
    public ResponseEntity<String> addHealthIndex(@RequestParam("healthIndex") HealthIndex healthIndex){
       int successNum = healthIndexRepository.addHealthIndex(healthIndex);
       if (successNum==1){
           return new ResponseEntity<String>("提交成功！",HttpStatus.OK);
       }else{
           throw new RuntimeException("add healthIndex failed");
       }
    }

    /**
     * 查询健康指标
     * @param guid
     */
    @GetMapping("/queryHealthIndex")
    public ResponseEntity<HealthIndex> queryHealthIndex(@RequestParam("guid") String guid){
        Preconditions.checkNotNull(guid);
        HealthIndex healthIndex = healthIndexRepository.getLastHealthIndex(guid);
        return new ResponseEntity<HealthIndex>(healthIndex,HttpStatus.OK);
    }

    /**
     * 变化趋势
     * 需要返回一个相对值的数组
    @GetMapping("/changeTrend")
    public ResponseEntity<?> getChangeTrend(@RequestParam){
        return null;
    }*/

}
